﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tunnel
{
    public partial class DeviceBase : PictureBox
    {
        public DeviceBase()
        {
            InitializeComponent();
            
        }
        
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }

        string tipString;

        string protocol;
        private void DeviceBase_MouseEnter(object sender, EventArgs e)
        {
            //tipString = "设备名称\r\n" + this.Name;
            Type childType = this.GetType();
            PropertyInfo piStatusDescription = childType.GetProperty("StatusDescription");
            PropertyInfo piStatusID = childType.GetProperty("StatusID");
            PropertyInfo piUpdateTime = childType.GetProperty("UpdateTime");
            PropertyInfo piDevicePos = childType.GetProperty("DevicePos");
            string statusDescription = (string)piStatusDescription.GetValue(this,null);
            string statusID = (string)piStatusID.GetValue(this, null);
            string updateTime = piUpdateTime.GetValue(this, null).ToString();
            string devicePos = piDevicePos.GetValue(this, null).ToString();
            tipString = this.Name + "\r\n当前状态：" + statusDescription + "\r\n" + updateTime+"\r\n位置:"+ devicePos;
            tpName.Show(tipString, this);
            
        }

        private void DeviceBase_MouseLeave(object sender, EventArgs e)
        {
            tpName.Hide(this);
        }
        Font font = new Font("微软雅黑", 15, FontStyle.Regular);

        public string Protocol
        {
            get
            {
                return protocol;
            }

            set
            {
                protocol = value;
            }
        }

        private void tpName_Draw(object sender, DrawToolTipEventArgs e)
        {
            e.DrawBackground();
            
            
            e.Graphics.DrawString(e.ToolTipText, font, Brushes.Black, new Point(0, 0));
        }

        private void tpName_Popup(object sender, PopupEventArgs e)
        {
            e.ToolTipSize = TextRenderer.MeasureText(tipString, font);
        }
    }
}
